package com.freda.oa.flow.run.model.impl;

import com.freda.oa.flow.run.model.itf.FlowHisTaskmodelItf;
import com.freda.oa.flow.run.model.itf.FlowInstanceModelItf;
import com.freda.oa.flow.run.model.itf.FlowManagerModelItf;
import com.freda.oa.flow.run.model.itf.FlowPartModelItf;
import com.freda.oa.flow.run.model.itf.FlowTaskModelItf;
import com.freda.oa.flow.run.vo.FlowRunInfoVo;

/**
 * 根据节点tape操作流程走向
 * @author Administrator
 *
 */
public class FlowManagerModelImpl extends FlowBaseModelImpl implements FlowManagerModelItf {
	/**
	 * 任务
	 */
	private FlowTaskModelItf task ;
	/**
	 * 历史
	 */
	private FlowHisTaskmodelItf hisTask ;
	/**
	 * 实例
	 */
	private FlowInstanceModelItf instance ;
	/**
	 * 参与者
	 */
	private FlowPartModelItf part ;
	
	/* (non-Javadoc)
	 * @see com.freda.oa.flow.run.model.impl.FlowManagerModelItf#nodeToEnd(com.freda.oa.flow.run.vo.FlowRunInfoVo)
	 */
	@Override
	public int nodeToEnd(FlowRunInfoVo runInfo)
	{
		
		instance.editInstance(runInfo);
		
		hisTask.editHisTask(runInfo);
		
		return 1;
	}

	/* (non-Javadoc)
	 * @see com.freda.oa.flow.run.model.impl.FlowManagerModelItf#silmpleToNext(com.freda.oa.flow.run.vo.FlowRunInfoVo)
	 */
	@Override
	public int silmpleToNext(FlowRunInfoVo runInfo)
	{
		this.nodeToEnd(runInfo);
		
		if(runInfo.getAssigneeId().indexOf(",") != -1)
		{
			String assIdStr = runInfo.getAssigneeId();
			String[] assId = assIdStr.split(",");
			
			runInfo.setAssigneeId("-1");
			
			hisTask.addHisTask(runInfo);
			
			task.editTask(runInfo);
			
			for(int i=0;i<assId.length;i++)
			{
				runInfo.setAssigneeId(assId[i]);
				part.addPart(runInfo);
			}
		}
		else
		{
			
		}
		
		return 0;
	}
	
	/* (non-Javadoc)
	 * @see com.freda.oa.flow.run.model.impl.FlowManagerModelItf#foreachTonext(com.freda.oa.flow.run.vo.FlowRunInfoVo)
	 */
	@Override
	public int foreachToNext(FlowRunInfoVo runInfo)
	{
		this.nodeToEnd(runInfo);
		
		return 0;
	}
	
	/* (non-Javadoc)
	 * @see com.freda.oa.flow.run.model.impl.FlowManagerModelItf#joinToNext(com.freda.oa.flow.run.vo.FlowRunInfoVo)
	 */
	@Override
	public int joinToNext(FlowRunInfoVo runInfo)
	{
		this.nodeToEnd(runInfo);
		
		return 0;
	}
	
	/* (non-Javadoc)
	 * @see com.freda.oa.flow.run.model.impl.FlowManagerModelItf#stateToNext(com.freda.oa.flow.run.vo.FlowRunInfoVo)
	 */
	@Override
	public int stateToNext(FlowRunInfoVo runInfo)
	{
		this.nodeToEnd(runInfo);
		
		return 0;
	}
	
	/* (non-Javadoc)
	 * @see com.freda.oa.flow.run.model.impl.FlowManagerModelItf#doPerusal(com.freda.oa.flow.run.vo.FlowRunInfoVo)
	 */
	@Override
	public int doPerusal(FlowRunInfoVo runInfo)
	{
		return 0;
	}
	
	/* (non-Javadoc)
	 * @see com.freda.oa.flow.run.model.impl.FlowManagerModelItf#perusalCompleted(com.freda.oa.flow.run.vo.FlowRunInfoVo)
	 */
	@Override
	public int perusalCompleted(FlowRunInfoVo runInfo)
	{
		return 0;
	}
	
	/* (non-Javadoc)
	 * @see com.freda.oa.flow.run.model.impl.FlowManagerModelItf#flowToEnd(com.freda.oa.flow.run.vo.FlowRunInfoVo)
	 */
	@Override
	public int flowToEnd(FlowRunInfoVo runInfo)
	{
		this.nodeToEnd(runInfo);
		
		return 0;
	}
	
	/* (non-Javadoc)
	 * @see com.freda.oa.flow.run.model.impl.FlowManagerModelItf#lockAssignee(com.freda.oa.flow.run.vo.FlowRunInfoVo)
	 */
	@Override
	public int lockAssignee(FlowRunInfoVo runInfo)
	{
		task.lockAssignee(runInfo);
		
		hisTask.lockAssignee(runInfo);
		
		return 0;
	}
	
	/* (non-Javadoc)
	 * @see com.freda.oa.flow.run.model.impl.FlowManagerModelItf#unLockAssignee(com.freda.oa.flow.run.vo.FlowRunInfoVo)
	 */
	@Override
	public int unLockAssignee(FlowRunInfoVo runInfo)
	{
		task.unLockAssignee(runInfo);
		
		hisTask.unLockAssignee(runInfo);
		
		return 0;
	}
	
	/* (non-Javadoc)
	 * @see com.freda.oa.flow.run.model.impl.FlowManagerModelItf#getFlowInfo(com.freda.oa.flow.run.vo.FlowRunInfoVo, java.lang.String)
	 */
	@Override
	public FlowRunInfoVo getFlowInfo(FlowRunInfoVo runInfo,String type)
	{
		return null;
	}
	
	@Override
	public int flowToStart(FlowRunInfoVo runInfo) {
		
		return 0;
	}
	
/**************** setter **********************/
	/**
	 * @param task the task to set
	 */
	public void setTask(FlowTaskModelItf task) {
		this.task = task;
	}

	/**
	 * @param hisTask the hisTask to set
	 */
	public void setHisTask(FlowHisTaskmodelItf hisTask) {
		this.hisTask = hisTask;
	}

	/**
	 * @param instance the instance to set
	 */
	public void setInstance(FlowInstanceModelItf instance) {
		this.instance = instance;
	}

	/**
	 * @param part the part to set
	 */
	public void setPart(FlowPartModelItf part) {
		this.part = part;
	}	
}
